<template>
  <div class="lot readonly" v-loading="loading">
    <el-row
      type="flex"
      :justify="$route.query.is_sealed == 2?'end':'start'"
      style="margin-bottom:10px;"
    >
      <div class="d-center">
        <el-button size="medium" type="primary" @click="add()" v-if="$route.query.is_sealed == 1">新增</el-button>
      </div>
      <div class="d-center" style="margin-left:10px;">
        <el-button
          size="medium"
          :type="selectData.length>0?'danger':'info'"
          @click="del()"
          v-if="$route.query.is_sealed == 1"
        >删除</el-button>
      </div>
      <el-button size="medium" type="info" v-if="$route.query.is_sealed == 2">已封存</el-button>
    </el-row>
    <el-table
      :data="tableData"
      style="width: 100%;border:1px solid #ccc;"
      height="100%"
      @selection-change="handleSelectionChange"
      ref="table"
    >
      <el-table-column type="selection" width="55" align="center"></el-table-column>
      <el-table-column label="项目名称" show-overflow-tooltip width="100" align="center">
        <template>
          <span>{{xmmc}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="bdmc" label="标段名称" show-overflow-tooltip width="100" align="center"></el-table-column>
      <el-table-column prop="zb_nrfl" label="招标内容分类" width="120" align="center"></el-table-column>
      <el-table-column prop="zb_xs" label="招标形式" width="100" align="center"></el-table-column>
      <el-table-column label="招标文件是否完成编制" width="200" align="center">
        <template slot-scope="scope">
          <PatternsSmall :iconShow="verification(scope.row.zb_wjbzwcrq?'green':'white')" />
        </template>
      </el-table-column>
      <el-table-column
        prop="zb_dlgs"
        label="招标代理机构"
        show-overflow-tooltip
        width="120"
        align="center"
      ></el-table-column>
      <el-table-column prop="gg_fbsj" label="公告发布日期" width="120" align="center"></el-table-column>
      <el-table-column prop="kb_sj" label="开标日期" width="100" align="center"></el-table-column>
      <el-table-column prop="zbsx" label="招标上限（万元）" width="200" align="center"></el-table-column>
      <el-table-column prop="zbj" label="中标价（万元）" width="200" align="center"></el-table-column>
      <el-table-column
        prop="zbdw_obj.dwmc"
        label="中标单位"
        show-overflow-tooltip
        width="100"
        align="center"
      ></el-table-column>
      <el-table-column label="评标报告是否报厅备案" width="200" align="center">
        <template slot-scope="scope">
          <PatternsSmall :iconShow="verification(scope.row.pbbgbtbarq?'green':'white')" />
        </template>
      </el-table-column>
      <el-table-column prop="pbbgbtbarq" label="评标报告报厅备案日期" width="200" align="center"></el-table-column>

      <el-table-column label="操作" fixed="right" width="250" align="center">
        <template slot-scope="scope">
          <el-button
            size="medium"
            type="primary"
            plain
            @click="edit(scope.row)"
            v-if="$route.query.is_sealed == 1"
          >编辑</el-button>
          <el-button size="medium" type="primary" plain @click="edit(scope.row)" v-else>查看</el-button>
          <el-button
            size="medium"
            type="primary"
            plain
            @click="setUp(scope.row)"
            v-if="$route.query.is_sealed == 1"
          >设置中标单位</el-button>
          <el-button size="medium" type="primary" plain @click="setUp(scope.row)" v-else>查看中标单位</el-button>
        </template>
      </el-table-column>
    </el-table>

    <lotDialog
      :dialogFormVisible1="dialogFormVisible1"
      @close="close1"
      :item="item"
      :inner="inner"
      :Xscode="Xscode"
    />
    <lotDetail
      :dialogFormVisible1="dialogFormVisible2"
      @close="close2"
      :item="item"
      :inner="inner"
      :Xscode="Xscode"
    />
    <transition name="delpop">
      <delPop @close="visible = false" v-if="visible" :data="deldata" />
    </transition>
  </div>
</template>

<script>
import lotDialog from "./dialog/lotDialog.vue";
import lotDetail from "./dialog/lotDetail.vue";
import delPop from "@/components/delPop";
import PatternsSmall from "@/components/patternsSmall";

export default {
  components: {
    lotDialog,
    lotDetail,
    delPop,
    PatternsSmall
  },
  data() {
    return {
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      tableData: [],
      selectData: [],
      loading: false,
      item: {},
      inner: [],
      Xscode: [],
      visible: false,
      deldata: {}
    };
  },
  methods: {
    verification(item) {
      item.toString();
      if (item.toString() == "green") {
        return 1;
      }
      if (item.toString() == "red") {
        return 2;
      }
      if (item.toString() == "white") {
        return 3;
      }
      if (item.toString() == "true") {
        return 4;
      }
      if (item.toString() == "false") {
        return 5;
      }
    },
    edit(item) {
      this.item = { ...item };
      this.dialogFormVisible1 = !this.dialogFormVisible1;
    },
    setUp(item) {
      this.item = { ...item };
      this.dialogFormVisible2 = !this.dialogFormVisible2;
    },
    look(item) {
      this.item = { ...item };
      this.dialogFormVisible1 = !this.dialogFormVisible1;
    },
    add() {
      this.item = {};
      this.dialogFormVisible1 = !this.dialogFormVisible1;
    },
    close1(item) {
      this.dialogFormVisible1 = false;
      if (item) {
        this.search();
      }
    },
    close2(item) {
      this.dialogFormVisible2 = false;
      if (item) {
        this.search();
      }
    },
    del() {
      if (!this.selectData.length) {
        this.$message({
          type: "error",
          message: "没有选中的条目"
        });
        return;
      }
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$post("/api/QqBdgl/deletesall", { id: this.selectData }).then(
            res => {
              if (res.code == 200) {
                this.deldata = res.data;
                setTimeout(() => {
                  this.visible = true;
                }, 400);
                this.search();
              } else {
                this.$message({
                  message: res.msg,
                  type: "error"
                });
              }
            }
          );
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    handleSelectionChange(value) {
      this.selectData = value;
    },
    search() {
      this.loading = true;
      this.$get("/api/QqBdgl/index", { xm_id: this.xm_id }).then(res => {
        if (res.code == 200 && res.data) {
          this.tableData = res.data;
        }
        this.$refs.table.bodyWrapper.scrollTop = 0;
        this.loading = false;
      });
    }
  },
  computed: {
    xm_id() {
      return this.$route.query.xm_id || this.$route.params.xm_id;
    },
    xmmc() {
      return this.$route.query.xmmc;
    }
  },
  mounted() {
    this.search();
    this.$get("/api/index/codes", { pid: 17 }).then(res => {
      if (res.code == 200 && res.data) {
        this.inner = res.data.list;
      }
    });
    this.$get("/api/index/codes", { pid: 25 }).then(res => {
      if (res.code == 200 && res.data) {
        this.Xscode = res.data.list;
      }
    });
  },
  watch: {
    xm_id() {
      this.search();
    }
  }
};
</script>

<style scoped lang="less">
.lot {
  width: 100%;
  height: 92%;
}
</style>